﻿using System;
using System.Collections.Generic;
using System.Text;
using com.lover.astd.common.logic;
using com.lover.astd.common.model.enumer;

namespace com.lover.astd.common.logicexe.activities
{
    public class PlayerCompeteExe : ExeBase
    {
        public PlayerCompeteExe() { _name = ConfigStrings.S_Player_Compete; _readable = ConfigStrings.SR_Player_Compete; }
        public override long execute()
        {
            Dictionary<string, string> conf = getConfig();
            if (!conf.ContainsKey(ConfigStrings.enabled) || !conf[ConfigStrings.enabled].ToLower().Equals("true")) return an_hour_later();
            bool _buy_reward = conf.ContainsKey(ConfigStrings.buy_reward) && conf[ConfigStrings.buy_reward].ToLower().Equals("true");
            ActivityMgr mgr = ServiceFactory.getActivityManager();

            if (_user.isActivityRunning(ActivityType.PlayerCompete))
            {
                int result = mgr.handlePlayerCompeteSignupInfo(_proto, _logger, _buy_reward, getGoldAvailable());
                if (result == 1) return next_hour();
                if (result == 10) return next_day();
                return next_hour();
            }
            if (_user.isActivityRunning(ActivityType.PlayerCompeteEvent))
            {
                int result = mgr.handlePlayerCompeteEventInfo(_proto, _logger, _buy_reward, getGoldAvailable());
                if (result == 1) return next_hour();
                if (result == 10) return next_day();
                return next_hour();
            }
            return next_hour();
        }
    }
}
